package com.menny.android.ongoingweather;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {
	private static final String TAG = "OngoingWeatherBootReceiver";
        @Override
        public void onReceive(Context context, Intent intent) {
                // just make sure we are getting the right intent (better safe than sorry)
                if( "android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
                        // Only start service if supposed to according to settings
                        if ( OngoingWeatherConfiguration.getInstance().getStartOnBoot() ) {
                                Log.i(TAG, "Received intent: android.intent.action.BOOT_COMPLETED");                       
                                
                                ComponentName comp = new ComponentName(context.getPackageName(), OngoingWeatherService.class.getName());
                                ComponentName service = context.startService(new Intent().setComponent(comp));
                                if (null == service){
                                        // something really wrong here
                                        Log.e(TAG, "Could not start service " + comp.toString());
                                }
                        }
                } else {
                        Log.e(TAG, "Received unexpected intent " + intent.toString());   
                }
        }
}
